Arrow Function
Features of Arrow Function
Lexical this
- The biggest difference from normal functions is how arrow functions handle
this. - In normal functions,
thisdepends on how the function is called (dynamic binding). - In arrow functions,
thisis taken from the surrounding scope (lexical binding). - Because of this, you cannot change
thisusingcall(),apply(), orbind()on an arrow function.
Cannot Be Used as Constructors
Arrow functions cannot be used with new.
They don’t have a prototype property, so you can’t create objects from them.
const Student = (name) => {
this.name = name;
};
const s1 = new Student("Masum"); // ❌ TypeError: Student is not a constructor
No arguments Object
In normal functions, you can use the special arguments object.
In arrow functions, arguments is not available (they inherit from parent scope if used).